package com.taobaolite.transaction;

import com.taobaolite.user.User;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.io.Serializable;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Objects;

@Embeddable
public class TransactionPK implements Serializable {
    @ManyToOne
    @JoinColumn(name = "userFrom")
    private User userFrom;
    @ManyToOne
    @JoinColumn(name = "userTo")
    private User userTo;
    @Column(updatable = false, nullable = false)
    private Timestamp time;

    public TransactionPK(User userFrom, User userTo, Timestamp time) {
        this.userFrom = userFrom;
        this.userTo = userTo;
        this.time = time;
    }

    public TransactionPK() {}



    public User getUserFrom() {
        return userFrom;
    }

    public void setUserFrom(User userFrom) {
        this.userFrom = userFrom;
    }


    public User getUserTo() {
        return userTo;
    }

    public void setUserTo(User userTo) {
        this.userTo = userTo;
    }

    public Timestamp getTime() {
        return time;
    }

    public void setTime(Timestamp time) {
        this.time = time;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TransactionPK modelKey = (TransactionPK) o;
        return Objects.equals(userFrom, modelKey.userFrom) &&
                Objects.equals(userTo, modelKey.userTo) &&
                Objects.equals(time, modelKey.time);
    }

    @Override
    public int hashCode() {
        return Objects.hash(time, userFrom, userTo);
    }
}
